var create_qrcode = function(text, typeNumber, errorCorrectLevel, table) {
	var qr = qrcode(typeNumber || 8, errorCorrectLevel || 'M');
		qr.addData(text);
		qr.make();

	//	return qr.createTableTag();
		return qr.createImgTag();

};


/*
	*  How to receive results in XML.
	*/

	google.load("feeds", "1");

	// Our callback function, for when a feed is loaded.
	function feedLoaded(result, category) {
		if (!result.error) {
			// Get and clear our content div.
			var content = document.getElementById(category);
			// Get all items returned.
			var items = result.xmlDocument.getElementsByTagName('item');

			printRSStoHTML(items, content);
		}
	}
	var autoid = 0;
	function printRSStoHTML(items, content) {
		autoid = autoid + 1;
		var tempHTML = '';
		tempHTML ='<ul class="articles contenuRubrique '+ autoid +'" style="cursor:wait;" id="cliquable">';
		// Loop through our items
		for (var i = 0; i < items.length; i++) {
			var item = items[i];
			
			// Get datas from XML RSS.
			var title = item.getElementsByTagName('title')[0].firstChild.nodeValue;
			var pubDate = new Date(item.getElementsByTagName('pubDate')[0].firstChild.nodeValue);
			var description = item.getElementsByTagName('description')[0].firstChild.nodeValue;
			var link = item.getElementsByTagName('link')[0].firstChild.nodeValue;
			if(item.getElementsByTagName('enclosure')[0]!=null){
				var thumbnail = item.getElementsByTagName('enclosure')[0].getAttribute('url');
			} else {
				var thumbnail = '';
			}
			
			tempHTML += '<li class=\'article' + (i+1) + '\'>';
			tempHTML += '<a class=\'body\'>';
			tempHTML += '<img src="' + thumbnail + '" class=\'pictureArticle\'>';
			tempHTML += '<img class=\'qrcode\' src="' + create_qrcode(link) + '" />';
			tempHTML += '<h1 class=\'title\'>' + title + '</h1>';
			tempHTML += '<h2 class=\'hour\'>' + pubDate.toLocaleDateString() + '</h2>';
			tempHTML += '<p class=\'summary\'>' + description + '</p>';
			tempHTML += '</a></li>';
		}
		tempHTML += '</ul>';
		content.innerHTML = tempHTML;
		//alert(tempHTML);
	}
	
	function loadFeed(feed, category) {
		// Create a feed instance that will grab Digg's feed.
		var feed = new google.feeds.Feed(feed);
		// Number of feed
		feed.setNumEntries(7);
		// Request the results in XML
		feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
		// Calling load sends the request off.  It requires a callback function.
		feed.load(function(result) { feedLoaded(result, category); } );
	}

	function OnLoad() {
		loadFeed("http://www.ladepeche.fr/rss/171.rss",'Politique');
		loadFeed("http://www.ladepeche.fr/rss/91.rss",'Loisirs');
		loadFeed("http://www.ladepeche.fr/rss/164.rss",'France');
		loadFeed("http://www.ladepeche.fr/rss/76.rss",'Actu');
		loadFeed("http://www.ladepeche.fr/rss/165.rss",'International');
		loadFeed("http://www.ladepeche.fr/rss/167.rss",'Faits Divers');
		loadFeed("http://www.ladepeche.fr/rss/168.rss",'Insolites');
	}

	google.setOnLoadCallback(OnLoad);
	
